#include <mzfc_inc.h>
#include <mzfc/SipHelper.h>

class MyScrollWin : public UiWin
{
public:

	int OnLButtonUp()
	{
		m_IsLButtonDown = false;

		return 1;
	}
	
	int OnLButtonDown(LPARAM lParam)
	{
		m_IsLButtonDown = true;

		m_LastMouseY = HIWORD(lParam);

		return 1;
	}

	bool OnMouseMove(LPARAM lParam)
	{
		if(m_IsLButtonDown)
		{
			int movedY = HIWORD(lParam) - m_LastMouseY;

			int newY = GetPosY() + movedY;

			if(newY > MZM_HEIGHT_CAPTION)
				newY = MZM_HEIGHT_CAPTION;
			else
			{
				UiWin* lastChild = this->GetChild(this->GetChildrenCount() - 1);

				int bottom = lastChild->GetRect().bottom + SETTINGWIN_TB_GAP;

				if(MzIsSipOpen() || g_IsNumberSipOpen)
				{
					int fix = 0;

					if(g_IsNumberSipOpen)
						fix = 77;

					RECT rect = MzGetVisibleDesktopRect();

					int minY = -(bottom - RECT_HEIGHT(rect) - fix);

					if(newY < minY)
						newY = minY;
				}
				else if(bottom > GetHeight())
				{
					int minY = -(bottom - GetHeight());

					if(newY < minY)
						newY = minY;
				}
				else
				{
					newY = GetPosY();
				}
			}

			SetPos(GetPosX(), newY, GetWidth(), GetHeight());

			this->Invalidate();

			return true;
		}

		return false;
	}

private:

	bool m_IsLButtonDown;

	CMouseTracker m_Mouse;

	int m_LastMouseY;
};